package com.goldenautumn.prefabricate.activity.cart.dialog

import android.content.Context
import android.view.ViewGroup
import com.chad.library.adapter4.BaseQuickAdapter
import com.chad.library.adapter4.viewholder.DataBindingHolder
import com.goldenautumn.prefabricate.R
import com.goldenautumn.prefabricate.business.entity.PaymentMethodVo
import com.goldenautumn.prefabricate.databinding.ItemPaymentMethodBinding
import qncx.external.common.compat.isVisible

class PaymentMethodAdapter : BaseQuickAdapter<PaymentMethodVo, DataBindingHolder<ItemPaymentMethodBinding>>() {

    var type:String? = null

    override fun onBindViewHolder(holder: DataBindingHolder<ItemPaymentMethodBinding>, position: Int, item: PaymentMethodVo?) {
        if(item == null) return
        var mBinding  = holder.binding
        if(type == item.value){
            mBinding.select.setImageResource(R.mipmap.ic_address_select)
        }  else {
            mBinding.select.setImageResource(R.mipmap.ic_address_not_select)
        }
        mBinding.icon.setImageResource(item.icon)
        mBinding.title.text = item.title
        mBinding.view.isVisible(position != items.size - 1)
    }

    override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): DataBindingHolder<ItemPaymentMethodBinding> {
        return DataBindingHolder(R.layout.item_payment_method,parent)
    }

}